package com.lire.shop.converter;

import com.lire.shop.data.Constants;
import com.lire.shop.entity.Order;
import com.lire.shop.entity.Product;
import com.lire.shop.entity.User;
import com.lire.shop.model.vo.OrderVO;
import org.mapstruct.InheritConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.Map;

@Mapper(componentModel = "spring")
public abstract class OrderConverter {
    public static final ChecklistConverter INSTANCE = Mappers.getMapper(ChecklistConverter.class);

    @InheritConfiguration
    public OrderVO do2vo(Order order, User user, Product product) {
        OrderVO orderVO = new OrderVO();
        orderVO.setOid(order.getOid());
        orderVO.setOrderNumber(order.getOrderNumber());
        orderVO.setPrice(product.getPrice());
        orderVO.setUsername(user.getUsername());
        orderVO.setProductName(product.getName());
        if (Constants.ORDER_PAID_BEEN.equals(order.getOrderStatus())) {
            orderVO.setOrderStatus("已付款");
        } else if (Constants.ORDER_PAID_BACK.equals(order.getOrderStatus())) {
            orderVO.setOrderStatus("已退款");
        } else {
            orderVO.setOrderStatus("未知状态");
        }
        return orderVO;
    }

}
